package com.example.aqarapp.view.adapter;

import android.view.View;
import android.widget.AdapterView;
import android.widget.Toast;

import androidx.annotation.NonNull;

import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.chad.library.adapter.base.BaseNodeAdapter;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.entity.MultiItemEntity;
import com.chad.library.adapter.base.entity.node.BaseNode;
import com.chad.library.adapter.base.listener.OnItemChildClickListener;
import com.chad.library.adapter.base.listener.OnItemClickListener;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.example.aqarapp.entity.BulbInfo;
import com.example.aqarapp.entity.CurtainInfo;
import com.example.aqarapp.entity.DeviceInfo;
import com.example.aqarapp.entity.OneBean;
import com.example.aqarapp.entity.SocketInfo;
import com.example.aqarapp.entity.TwoBean;

import java.util.List;

import aqarapp.R;

public class DeviceListDeivceItemAdapter extends BaseNodeAdapter {

    public static final int TYPE_ONE = 0;
    public static final int TYPE_TWO = 1;

    public DeviceListDeivceItemAdapter() {
        super();
        // 绑定 layout 对应的 type
        addNodeProvider(new FirstProvider());
        addNodeProvider(new SecondProvider());
        addChildClickViewIds(R.id.test_device_list_view);

    }



    //    @Override
//    protected void convert(@NonNull BaseViewHolder baseViewHolder, MultiItemEntity multiItemEntity) {
//
//        switch (baseViewHolder.getItemViewType()) {
//            case TYPE_ONE:
//                OneBean oneBean = (OneBean) multiItemEntity;
//                baseViewHolder.setText(R.id.test_roomName,oneBean.getTitle());
//                break;
//            case TYPE_TWO:
//                DeviceInfo deviceInfo = ((DeviceInfo)multiItemEntity);
//                if (deviceInfo.getBaseDeviceInfo() instanceof BulbInfo) {
//                    baseViewHolder.setBackgroundResource(R.id.test_device_list_info_iv, R.mipmap.lightbulb_icon);
//                    baseViewHolder.setText(R.id.test_device_list_info_tv, deviceInfo.DeviceName);
//                } else if (deviceInfo.getBaseDeviceInfo() instanceof SocketInfo) {
//                    baseViewHolder.setBackgroundResource(R.id.test_device_list_info_iv, R.mipmap.socket);
//                    baseViewHolder.setText(R.id.test_device_list_info_tv, deviceInfo.DeviceName);
//                } else if (deviceInfo.getBaseDeviceInfo() instanceof CurtainInfo) {
//                    baseViewHolder.setBackgroundResource(R.id.test_device_list_info_iv, R.mipmap.curtain);
//                    baseViewHolder.setText(R.id.test_device_list_info_tv, deviceInfo.DeviceName);
//                }
//                break;
//            default:
//                break;
//        }
//    }

    @Override
    protected int getItemType(@NonNull List<? extends BaseNode> list, int i) {
        BaseNode node = list.get(i);
        if (node instanceof OneBean) {
            return 1;
        } else if (node instanceof DeviceInfo) {
            return 2;
        }
        return -1;
    }
}
